<?php
    /*
     * 全局方法
     */
    /*
     * 检查sql的合法性
     */
function inject_check($sql_str) { //防止注入
    $check = eregi('select|insert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile', $sql_str);
    
    return $check ? false : true;
}

/*
 *获得客户端真实的IP地址
 */
function getip() {
    if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) {
        $ip = getenv("HTTP_CLIENT_IP");
    } else
        if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) {
            $ip = getenv("HTTP_X_FORWARDED_FOR");
        } else
            if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) {
                $ip = getenv("REMOTE_ADDR");
            } else
                if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) {
                    $ip = $_SERVER['REMOTE_ADDR'];
                } else {
                    $ip = "unknown";
                }
    return ($ip);
}

/*
 * 停止脚本执行
 */
function shutDown($msg) {
    ENV=='dev' ? exit($msg) : exit();
}

function pages($total=0, $pageSize=10) {
    include_once (KJ_PATH.'libs/page.class.php');
    $page = new page($total, $pageSize);
    return $pages = $page->fpage();
}
